﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HSDc.DefinitionTransformer.Entity
{
    
    internal class Process
    {
        private string _guid;

        public string Guid
        {
            get { return _guid; }
            set { _guid = value; }
        }

        private int _Id;

        public int Id
        {
            get { return _Id; }
            set { _Id = value; }
        }

        private int _eofId;

        public int EofId
        {
            get { return _eofId; }
            set { _eofId = value; }
        }

        private string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private int _version;

        public int Version
        {
            get { return _version; }
            set { _version = value; }
        }
        private bool _active;

        public bool Active
        {
            get { return _active; }
            set { _active = value; }
        }
        private int _status;

        public int Status
        {
            get { return _status; }
            set { _status = value; }
        }

        private string _source = string.Empty;

        public string Source
        {
            get { return _source; }
            set { _source = value; }
        }

        private List<Transition> _transitions;

        public List<Transition> Transitions
        {
            get { return _transitions; }
            set { _transitions = value; }
        }

        List<ProcessElement> _connectedElements;

        internal List<ProcessElement> ConnectedElements
        {
            get { return _connectedElements; }
            set { _connectedElements = value; }
        }

        private List<Swimlane> _swimlanes;

        public List<Swimlane> Swimlanes
        {
            get { return _swimlanes; }
            set { _swimlanes = value; }
        }

        public Process()
        {
            _connectedElements = new List<ProcessElement>();
            _transitions = new List<Transition>();
            _swimlanes = new List<Swimlane>();
            _guid = System.Guid.NewGuid().ToString();
        }

        public Swimlane FindElementBelongSwimlane(int parentId) 
        {

            var result = from s in this.Swimlanes where s.Id == parentId select s;
            foreach (var item in result)
                return item;
   
            return null;
        }

        public ProcessElement FindConnectedProcessElement(int elementId) 
        {
            var result = from p in ConnectedElements where p.Id == elementId select p;
            foreach (var item in result)
                return item;

            return null;
        }

        public int FindMaxSwimlaneSeqNo()
        {
            var result = from p in Swimlanes  orderby p.SeqNo descending select p ;
            
            foreach (var item in result)
                return item.SeqNo;

            return 0;
        }
     

    }
}
